import { createWebHistory, createRouter } from 'vue-router'
// 引入路由守卫
import { routerGuard } from './auth.guard'

import Layout from '../views/Main.vue'
import Login from '../views/Login/index.vue'
import Admin from '../views/Auth/admin/index.vue'
import Group from '../views/auth/group/index.vue'
import Order from '../views/vppz/order/index.vue'   // 修改此处
import Staff from '../views/vppz/staff/index.vue'  // 修改此处
import Dashboard from '../views/dashboard/index.vue'

const routes = [
    {
        path: '/', component: Layout,
        name: 'Main', // 默认子路由
        children: [  // 修正：children 应为小写
            {
                path: "dashboard",
                meta: { id: '1', name: '控制台', icon: 'platform', path: '/dashboard', describe: '系统控制台' },
                component: Dashboard
            },
            {
                path: "auth",
                meta: { id: '2', name: '权限管理', icon: 'Grid' },
                children: [  // 修正：children 小写
                    {
                        path: "",
                        alias: ['admin'],
                        meta: { id: '1', name: '账号管理', icon: 'Avatar', path: '/auth/admin', describe: '权限管理' },
                        component: Admin
                    },
                    {
                        path: "group",
                        meta: { id: '2', name: '菜单管理', icon: 'Menu', path: '/auth/group', describe: '菜单管理' },
                        component: Group
                    }
                ]
            },
            {
                path: 'vppz',
                meta: { id: '3', name: 'DIDI陪诊', icon: 'BellFilled' },
                children: [
                    {
                        path: '',
                        alias: ['staff'],
                        meta: { id: '1', name: '陪护管理', icon: 'Checked', path: '/vppz/staff', describe: '陪护管理' },
                        component: Staff
                    },
                    {
                        path: 'order',
                        meta: { id: '2', name: '订单管理', icon: 'Document', path: '/vppz/order', describe: '订单管理' },
                        component: Order
                    }
                ]
            }
        ]
    },
    {
        path: '/login',
        component: Login
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

// 路由守卫
routerGuard(router)

export default router